<template>
    <div class="table">
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item><i class="el-icon-lx-calendar"></i>商户管理</el-breadcrumb-item>
                <el-breadcrumb-item>商户列表</el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <div class="handle-box">
                <el-form :inline="true" ref="formQuery" :model="formQuery" class="demo-form-inline" label-width="100px">
                    <el-form-item label="代理商列表">
                        <el-select v-model="formQuery.agentId" placeholder="请选择">
                            <el-option
                            v-for="item in agentList"
                            :key="item.id"
                            :label="item.name"
                            :value="item.id">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <!-- <el-form-item label="商户编号">
                        <el-input v-model="formQuery.merNo" placeholder="商户编号"></el-input>
                    </el-form-item> -->
                    <el-form-item label="商户名称">
                        <el-input v-model="formQuery.merchantName" placeholder="商户名称"></el-input>
                    </el-form-item>
                    <!-- <el-form-item label="创建时间">
                        <el-date-picker
                          v-model="formQuery.creatTime"
                          type="daterange"
                          align="right"
                          unlink-panels
                          range-separator="至"
                          start-placeholder="开始日期"
                          end-placeholder="结束日期">
                        </el-date-picker>
                    </el-form-item> -->
                    <el-button type="primary" icon="search" @click="onSubmit">查询</el-button>
                </el-form>
            </div>
            <div class="handle-box">
                <el-button type="primary" icon="delete" class="handle-del mr10" @click="handleAdd()">新建</el-button>
            </div>
            <el-table :data="tableData" border class="table" ref="multipleTable" :row-class-name="tableRowClassName">
                <el-table-column prop="id" label="商户编号" align="center" width="150">
                </el-table-column>
                <el-table-column prop="name" label="商户名称" width="120" align="center">
                </el-table-column>
                <el-table-column prop="agentName" label="所属代理商" width="120" align="center">
                </el-table-column>
                <el-table-column prop="mobile" label="联系手机" width="200" align="center">
                </el-table-column>
                <el-table-column prop="province" label="归属省" width="200" align="center">
                </el-table-column>
                <el-table-column prop="city" label="归属市" width="200" align="center">
                </el-table-column>
                <el-table-column prop="creatTime" :formatter="filterDate" label="创建时间" width="200" align="center">
                </el-table-column>
                <el-table-column
                  fixed="right"
                  label="操作"
                >
                  <template slot-scope="scope">
                    <el-button @click="handleQuery(scope.row)" type="text" size="small">查看</el-button>
                    <el-button @click="handleEdit(scope.row)" type="text" size="small">编辑</el-button>
                  </template>
                </el-table-column>
            </el-table>
            <div class="pagination">
                <el-pagination background @current-change="handleCurrentChange" layout="prev, pager, next" :total="pageData.total" :page-size="pageData.pageSize">
                </el-pagination>
            </div>
        </div>

  <!--       编辑弹出框
  <el-dialog title="编辑" :visible.sync="editVisible" width="30%">
      <el-form ref="form" :model="form" label-width="100px">
          <el-form-item label="姓名">
              <el-input v-model="form.name"></el-input>
          </el-form-item>
          <el-form-item label="手机号">
              <el-input v-model="form.mobile"></el-input>
          </el-form-item>
          <el-form-item label="所属角色">
              <el-select v-model="form.role" placeholder="请选择">
                  <el-option key="0" label="管理员" value="0"></el-option>
                  <el-option key="1" label="代理商" value="1"></el-option>
                  <el-option key="2" label="商户" value="2"></el-option>
              </el-select>
          </el-form-item>
          <el-form-item label="状态">
              <el-select v-model="form.states" placeholder="请选择">
                  <el-option key="0" label="冻结" value="0"></el-option>
                  <el-option key="1" label="正常" value="1"></el-option>
              </el-select>
          </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
          <el-button @click="editVisible = false">取 消</el-button>
          <el-button type="primary" @click="saveEdit">确 定</el-button>
      </span>
  </el-dialog> -->

<!--         删除提示框
<el-dialog title="提示" :visible.sync="delVisible" width="300px" center>
    <div class="del-dialog-cnt">删除不可恢复，是否确定删除？</div>
    <span slot="footer" class="dialog-footer">
        <el-button @click="delVisible = false">取 消</el-button>
        <el-button type="primary" @click="deleteRow">确 定</el-button>
    </span>
</el-dialog> -->
    </div>
</template>
<script>
    import moment from 'moment'
    export default {
        name: 'basetable',
        data() {
            return {
                url: './static/vuetable.json',
                tableData: [],
                editVisible: false,
                delVisible: false,
                pageData: {
                    total: 0,
                    pageSize: 10,
                },
                formQuery: {
                    pageNo: 1,      // 当前页数
                    agentId: '',  // 选择的代理商
                    merchantName: ''     // 商户名称
                },
                form: {
                    role: '',
                    name: '',
                    mobile: '',
                    states: ''
                }
            }
        },
        created() {
            // this.getData();
        },
        mounted() {
            this.getAllData()
        },
        methods: {
            tableRowClassName({row, rowIndex}) {
                if (rowIndex === 1) {
                    return 'warning-row';
                } else if (rowIndex === 3) {
                    return 'success-row';
                }
                return '';
            },
            // 分页导航
            handleCurrentChange(val) {
                this.formQuery.pageNo = val;
                this.getData();
            },
            async getAllData() {
                let res1 = await this.request('allAgentList')
                this.agentList = res1.data
                this.formQuery.agentId = res1.data[0].id
                this.getData()
            },
            async getData() {   // 获取数据
                let res = await this.request('merchantList', this.formQuery)
                this.tableData = res.data.list
                this.pageData = {
                    total: res.data.total,
                    pageSize: res.data.pageSize
                }
            },
            onSubmit() {
                this.getData()
            },
            filterDate(row, column) {
                let time = moment(row.creatTime).format('YYYY-MM-DD')
                return time;
            },
            handleAdd() {
                this.$router.push('/merchantInfo');
            },
            handleQuery(val) {
                const record = val.id;
                this.$router.push(`/merchantInfo?action=query&id=${record}`);
            },
            handleEdit(val) {
                const record = val.id;
                this.$router.push(`/merchantInfo?action=edit&id=${record}`);
            }
        }
    }

</script>

<style scoped>
    .handle-box {
        margin-bottom: 20px;
    }

    .handle-select {
        width: 120px;
    }

    .handle-input {
        width: 300px;
        display: inline-block;
    }
    .del-dialog-cnt{
        font-size: 16px;
        text-align: center
    }
    .table{
        width: 100%;
        font-size: 14px;
    }
    .red{
        color: #ff0000;
    }
    .el-table .warning-row {
        background: oldlace;
    }

    .el-table .success-row {
        background: #f0f9eb;
    }
</style>
